# coding: utf-8
import sys

from PySide6.QtWidgets import QApplication, QVBoxLayout, QWidget, QLineEdit
from qfluentwidgets import SingleDirectionScrollArea, BodyLabel
from PySide6.QtCore import Qt

from qelwidgets import (ElLineEdit, ElSearchLineEdit, ElTextEdit, ElPasswordLineEdit, ElPlainTextEdit, ElTextBrowser,
                        ElPrimaryButton, ElIcon)


class Demo(SingleDirectionScrollArea):
    def __init__(self):
        super().__init__()
        self.view = QWidget()
        self.verticalLayout = QVBoxLayout(self.view)

        self.verticalLayout.addWidget(BodyLabel("普通输入框", self))
        self.lineEdit = ElLineEdit(self)
        self.lineEdit.setPlaceholderText("请输入内容")
        self.lineEdit.setClearButtonEnabled(True)
        self.verticalLayout.addWidget(self.lineEdit)

        self.verticalLayout.addWidget(BodyLabel('搜索输入框', self))
        self.lineEdit_2 = ElSearchLineEdit(self)
        self.lineEdit_2.setPlaceholderText("请输入内容")
        self.lineEdit_2.setClearButtonEnabled(True)
        self.lineEdit_2.setSearchButtonPosition(QLineEdit.ActionPosition.LeadingPosition)
        self.verticalLayout.addWidget(self.lineEdit_2)

        self.verticalLayout.addWidget(BodyLabel('多行输入框', self))
        self.lineEdit_3 = ElTextEdit(self)
        self.lineEdit_3.setPlaceholderText("请输入内容")
        self.verticalLayout.addWidget(self.lineEdit_3)

        self.verticalLayout.addWidget(BodyLabel('密码输入框', self))
        self.lineEdit_4 = ElPasswordLineEdit(self)
        self.lineEdit_4.setPlaceholderText("请输入密码")
        self.verticalLayout.addWidget(self.lineEdit_4)

        self.verticalLayout.addWidget(BodyLabel('纯文本输入框', self))
        self.lineEdit_5 = ElPlainTextEdit(self)
        self.lineEdit_5.setPlaceholderText("请输入内容")
        self.verticalLayout.addWidget(self.lineEdit_5)

        self.verticalLayout.addWidget(BodyLabel('文本浏览框', self))
        self.lineEdit_6 = ElTextBrowser(self)
        self.lineEdit_6.setPlaceholderText("请输入内容")
        self.verticalLayout.addWidget(self.lineEdit_6)

        self.verticalLayout.addWidget(BodyLabel('禁用状态', self))
        self.lineEdit_7 = ElLineEdit(self)
        self.lineEdit_7.setPlaceholderText("请输入内容")
        self.lineEdit_7.setClearButtonEnabled(True)
        self.lineEdit_7.setDisabled(True)
        self.verticalLayout.addWidget(self.lineEdit_7)

        self.verticalLayout.addWidget(BodyLabel('复合输入框', self))
        self.lineEdit_8 = ElLineEdit(self)
        self.lineEdit_8.setPlaceholderText("请输入内容")
        self.lineEdit_8.setLayoutSpacing(0)
        self.lineEdit_8.setLayoutContentsMargins(0, 0, 0, 0)
        prefixLabel = BodyLabel('前缀', self)
        prefixLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
        prefixLabel.setFixedWidth(50)
        self.lineEdit_8.addWidget(prefixLabel, QLineEdit.ActionPosition.LeadingPosition)
        button = ElPrimaryButton(ElIcon.Apple, '按钮', self)
        button.setFixedSize(200, 40)
        self.lineEdit_8.addWidget(button, QLineEdit.ActionPosition.LeadingPosition)
        suffixLabel = BodyLabel('后缀', self)
        suffixLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
        suffixLabel.setFixedWidth(50)
        self.lineEdit_8.setClearButtonEnabled(True)
        self.lineEdit_8.addWidget(suffixLabel, QLineEdit.ActionPosition.TrailingPosition)
        self.verticalLayout.addWidget(self.lineEdit_8)

        self.__initWidgets()

    def __initWidgets(self):
        self.setWindowTitle("Element Line Edit Demo")
        self.setWidget(self.view)
        self.setWidgetResizable(True)
        self.view.setAutoFillBackground(False)
        self.enableTransparentBackground()
        self.resize(1400, 800)


if __name__ == '__main__':
    app = QApplication()
    demo = Demo()
    demo.setStyleSheet('Demo {background-color: #ffffff;}')
    demo.show()
    sys.exit(app.exec())
